<template>
<div class="admin-edit-pwd">
	<Form ref="adminPwd" :model="detailInfo" :rules="adminValidate" action="javascript:void(0)">
		<FormItem label="密码" prop="password">
			<Input v-model="detailInfo.password" type="password" placeholder="输入密码..."></Input>
		</FormItem>
		<FormItem label="确认密码">
			<Input v-model="detailInfo.repassword" type="password" placeholder="确认密码..."></Input>
		</FormItem>
		<FormItem>
			<Button type="primary" @click="handleSubmit('adminPwd')">提交</Button>
		</FormItem>
	</Form>
</div>
</template>


<script>
import { LOGOUT, LOGIN } from '../.././store/mutation_types'
export default {
	name: 'AdminEditPwd',
	data() {
		return {
			detailInfo: {
				password: '',
				repassword: ''
			},
			adminValidate: {
				password: [
					{ required: true, message: '密码必须填写', trigger: 'blur' },
					{ type: 'string', min: 6, max: 15, message: '密码 6 - 15 位长度', trigger: 'blur' }
				]
			}
		}
	},
	created() {},
	methods: {
		handleSubmit(name) {
			this.$refs[name].validate((valid) => {
				if (valid) {
				var params = this.detailInfo;
				params.id = this.$store.getters.user_id;
				this.$api.admin.selfeditpassword(params).then(res => {
                    this.$store.commit(LOGOUT)
                    // 跳转到登录
                    this.$router.push('/');
				});
				}
			})
		}
	}
}
</script>
